package com.tssup.fesco.common.config.mvc;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

/**
 * Created by ansion on 16/8/17.
 */
public class TraceIdInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
//        HessianContext.clear();
//        HessianContext.setNeedClear(false);
//        Enumeration enumeration = httpServletRequest.getHeaderNames();
//        while (enumeration.hasMoreElements()) {
//            String name = enumeration.nextElement().toString();
//            String value = httpServletRequest.getHeader(name);
//
//            if (TRACE_ID.equalsIgnoreCase(name)) {
//                HessianContext.current().put(TRACE_ID, value);
//                break;
//            }
//        }
//
//        if (HessianContext.get(TRACE_ID) == null) {
//            HessianContext.current().put(TRACE_ID, HessianContext.getTraceId());
//        }

        return true;
    }

    @Override
    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {

    }
}
